MsgN("-- player.lua loaded")

local _ply = FindMetaTable("Player")

function _ply:SpendCash( amount )
	self:SetCash( self:GetCash() - amount )
end

function _ply:GiveCash( amount )
	self:SetCash( self:GetCash() + amount )
end

function _ply:SetCash( amount )
	self:SetPData("Cash", math.Clamp(amount, 0, MDF.MaximumCash))
end

function _ply:GetCash()
	return tonumber(self:GetPData("Cash") or MDF.MinimumCash)
end

function _ply:DropAll()
	self:StripWeapons()		--remove all weapons
	self:RemoveAllAmmo()	--remove all ammo
end

function _ply:Loadout()
	self:GiveAmmo(9999, "Pistol")
	self:Give( "weapon_pistol" )

	self.Weapons = (self:GetPData( "Weapons") or {})

	for model, info in pairs( list.Get("FloodWeapons") ) do
		local weapon = info.weapon

		if (table.HasValue( self.Weapons, weapon)) then
			--give weapon ammo
			self:GiveAmmo( info.ammo[1], info.ammo[2] )

			--give weapon
			self:Give( weapon )
		end
	end
end

function _ply:BuildTools()
	self:Give( "weapon_physgun" )
	self:Give( "weapon_physcannon" )
	self:Give( "gmod_tool" )

 	local cl_defaultweapon = self:GetInfo( "cl_defaultweapon" )

 	if (self:HasWeapon(cl_defaultweapon)) then self:SelectWeapon(cl_defaultweapon) end
end


function _ply:SaveWeapon( name )
	if (!self:GetPData("Weapons")) then self:SetPData("Weapons", {}) end

	if (table.HasValue(self:GetPData( "Weapons"), name)) then return end

	table.insert( self.Weapons, name )

	self:SetPData( "Weapons", self.Weapons )
end